<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>登录状态检查示例</title>
    <script>        document.addEventListener('DOMContentLoaded', function() {
        // 页面加载完成后发送请求
        checkLoginStatus();
    });

    async function checkLoginStatus() {
        try {
            const response = await fetch('/v1/users/currentUser');
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            const data = await response.json();
            updateUI(data);
        } catch (error) {
            console.error('Error checking login status:', error);
        }
    }

    function updateUI(data) {
        const loginStatusDiv = document.getElementById('login-status');
        const logoutButton = document.getElementById('logout-button');

        if (data.status === 'logged-in') {
            loginStatusDiv.textContent = data.message;
            logoutButton.style.display = 'block';
        } else {
            loginStatusDiv.textContent = data.message;
            logoutButton.style.display = 'none';
        }
    }
    </script>
</head>
<body>
<h1>欢迎来到我们的网站！</h1>
<div id="login-status"></div>
<button id="logout-button" style="display: none;">退出登录</button>
</body>
</html>